package a02staticdemo2;

import java.util.ArrayList;

public class ArrayUtil {
    private ArrayUtil(){}

    //定义静态方法,用于输出该数组的元素
    public static String printarr(int[] arr){
        StringBuilder sb = new StringBuilder();

        sb.append("[");
        for (int i = 0; i < arr.length; i++) {
            if(i == arr.length - 1)
                sb.append(arr[i]);
            else
                sb.append(arr[i] + ", ");
        }
        sb.append("]");
        return sb.toString();
    }

    //定义静态方法,用于求该数组的平均值
    public static double getAvg(double[] arr){
        double sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        return sum / arr.length;
    }
}
